﻿/*
 * Created by SharpDevelop.
 * User: thanh.nguyenchi
 * Date: 12/2/2011
 * Time: 9:09 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System.Collections.Generic;
using System.Threading;
using System;

namespace VDataAdapter.BlockingQueue
{
	/// <summary>
	/// Description of DataQueue.
	/// </summary>
	public class DataQueue
	{
		
	    public static int TIME_OUT_INTERVAL = 3000;
		
	    Queue<BaseObject> que = new Queue<BaseObject>();
	    Semaphore sem = new Semaphore(0, Int32.MaxValue);
	
	    public BaseObject get() {
	        BaseObject sData = null;
	        try{
	            sem.WaitOne();
		
		        lock (que)
		        {
		        	return que.Dequeue();
		        }
	        }
	        catch(Exception ex){
	        }		
	        return sData;
	    }
	
	    public void put(BaseObject sData){
	        try{
	    		lock (que)
		        {
		            que.Enqueue(sData);
		        }
		        sem.Release();                
	        }
	        catch(Exception ex){}
	    }
	
	    public int getQueueSize(){
	    	return que.Count;
	    }
	}
}
